<?php 
class agentClassAction extends Action
{
	public function dataAction()
	{
		$table = 'agent';
		$where = 'and `platid`='.$this->adminid.'';
		$sql 	= 'select * from [Q]'.$table.' where 1=1 '.$where.'';
		$total	= 0;
		$rows	= $this->db->getall($sql);
		$fobj	= m('file');
		foreach($rows as $k=>$rs){
			$rows[$k]['filecount'] = $fobj->rows('`agentid`='.$rs['id'].'');
		}
		
		$barr = array(
			'rows' => $rows,
			'totalCount'=> $total,
			'success' => true
		);
		return $barr;
	}
	
	public function formAction()
	{
		$id = (int)$this->get('id','0');
		$this->smartydata['id'] = $id;
		$this->smartydata['ming'] = '';
		$this->smartydata['urlaaa'] = '';
		if($id>0){
			$rs = m('agent')->getone('`id`='.$id.' and `platid`='.$this->adminid.'');
			if($rs){
				$this->smartydata['ming'] = $rs['name'];
				$this->smartydata['urlaaa'] = $rs['url'];
			}
		}
	}
	
	public function savecheckAction()
	{
		$ming = $this->post('ming');
		$id = (int)$this->post('id','0');
		$uarr= array(
			'name' 	=> $ming,
			'platid' => $this->adminid,
			'url' 	=> $this->post('url'),
			'status' => 1,
			'optdt' => $this->rock->now
		);
		$where = '`id`='.$id.' and `platid`='.$this->adminid.'';
		if($id==0){
			$where = '';
			$uarr['agentkey'] = md5($this->rock->jm->getRandkey());
		}
		$bo 	= m('agent')->record($uarr, $where);
		if(!$bo)return $this->db->error();
		
		return 'ok';
	}
	
}